package com.zjj.algorithm.learning.niuke;

import java.util.Scanner;

/**
 * @author zjj_admin
 * @date 2023/2/8 22:59
 */
public class Test48 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        String[] split = s.split(" ");
        Node head = null;
        for (int i = 2; i < split.length - 1; i += 2) {
            int val1 = Integer.parseInt(split[i]);
            int val2 = Integer.parseInt(split[i + 1]);
            if (i == 2) {
                head = new Node(val2);
                head.next = new Node(val1);
            } else {
                Node node1 = new Node(val1);
                Node node2 = new Node(val2);
                Node curr = head;
                while (curr != null) {
                    if (curr.val == node2.val) {
                        Node temp = curr.next;
                        curr.next = node1;
                        curr = curr.next;
                        curr.next = temp;
                    } else {
                        curr = curr.next;
                    }
                }
            }
        }
        Node dump = new Node(-1);
        dump.next = head;
        Node curr = dump;
        while (curr.next != null) {
            if (curr.next.val == Integer.parseInt(split[split.length - 1])) {
                curr.next = curr.next.next;
            }
            curr = curr.next;
        }
        Node now = dump.next;
        while (now != null) {
            System.out.print(now.val + " ");
            now = now.next;
        }
    }
}

class Node {
    int val;
    Node next;

    public Node(int val) {
        this.val = val;
        this.next = null;
    }
}
